<template>
  <div class="mapping-page">
    <!-- 头部盒子 -->
    <div class="header">
      <!-- 页面标题 -->
      <div class="title">
        <h4>权限分配</h4>
      </div>
      <div class="right">
        <!-- 搜索表单 -->
        <el-form :inline="true" size="small" style="display: inline-block">
          <el-form-item>
            <el-input placeholder="小组名称"></el-input>
          </el-form-item>
          <!-- <el-form-item>
            <el-input placeholder="AppName"></el-input>
          </el-form-item>-->
          <el-form-item>
            <el-button type="primary">查询</el-button>
          </el-form-item>
        </el-form>
        <!-- 新增按钮 -->
        <el-button size="small" style="height:32px" type="primary" plain @click="add">新增</el-button>
      </div>
    </div>

    <!-- table表格 -->
    <div class="table">
      <el-table :data="list" border style="width: 100%" height="500">
        <el-table-column prop="date" label="小组ID" width="100"></el-table-column>
        <el-table-column prop="name" label="小组名称"></el-table-column>
        <el-table-column prop="name" label="权限标识"></el-table-column>

        <el-table-column prop="address" label="描述"></el-table-column>

        <el-table-column prop label="操作" width="180">
          <template>
            <el-link type="primary" :underline="false" @click="assignmentPermissions">分配权限</el-link>
            <el-link type="primary" style="margin:0 5px" :underline="false" @click="edit">编辑</el-link>
            <el-link type="primary" :underline="false">删除</el-link>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 新增和编辑的对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="showDialog"
      width="35%"
      :before-close="handleCloseDialog"
    >
      <el-form label-width="80px" style="width:80%">
        <el-form-item label="小组名称">
          <el-input></el-input>
        </el-form-item>
        <el-form-item label="权限标识">
          <el-input></el-input>
        </el-form-item>
        <el-form-item label="小组描述">
          <el-input></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary">保存</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 分配权限的对话框 -->
    <el-dialog
      title="分配权限"
      :visible.sync="permissionsDialog"
      width="40%"
      :before-close="handleClosePermissionsDialog"
    >
      <el-tree
        check-strictly
        :data="data"
        show-checkbox
        node-key="id"
        default-expand-all
        :props="defaultProps"
      ></el-tree>
      <el-row slot="footer" type="flex" justify="center">
        <el-col :span="6">
          <el-button type="primary" size="mini" @click="btnPermissionOK">确定</el-button>
          <el-button size="mini" @click="permissionsDialog = false">取消</el-button>
        </el-col>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [
        {
          date: "1",
          name: "小组一",
          address: "这是小组一",
          state: 1
        },
        {
          date: "2",
          name: "小组二",
          address: "这是小组二",
          state: 0
        },
        {
          date: "3",
          name: "小组三",
          address: "这是小组三",
          state: 1
        },
        {
          date: "4",
          name: "小组四",
          address: "这是小组四",
          state: 0
        }
      ],

      data: [
        {
          id: 1,
          label: "一级 1",
          children: [
            {
              id: 4,
              label: "二级 1-1",
              children: [
                {
                  id: 9,
                  label: "三级 1-1-1"
                },
                {
                  id: 10,
                  label: "三级 1-1-2"
                }
              ]
            }
          ]
        },
        {
          id: 2,
          label: "一级 2",
          children: [
            {
              id: 5,
              label: "二级 2-1"
            },
            {
              id: 6,
              label: "二级 2-2"
            }
          ]
        },
        {
          id: 3,
          label: "一级 3",
          children: [
            {
              id: 7,
              label: "二级 3-1"
            },
            {
              id: 8,
              label: "二级 3-2"
            }
          ]
        }
      ],
      defaultProps: {
        children: "children",
        label: "label"
      },
      title: "新增",
      showDialog: false,
      permissionsDialog: false,
      state: true
    };
  },

  methods: {
    // 封装一个处理弹窗关闭的方法：需要关闭的时候调用，清楚表单的数据，初始化表单
    handleCloseDialog() {
      this.showDialog = false;
    },
    cancel() {
      this.showDialog = false;
    },
    edit() {
      this.title = "编辑";
      this.showDialog = true;
    },
    add() {
      this.title = "新增";
      this.showDialog = true;
    },
    viewPage() {
      this.showDrawer = true;
    },
    handleClosePermissionsDialog() {
      this.permissionsDialog = false;
    },
    // 分配权限
    assignmentPermissions() {
      this.permissionsDialog = true;
    }
  }
};
</script>

<style lang="scss" scoped>
.mapping-page {
  background-color: #fff;
  padding: 0 50px 50px 50px;

  .header {
    display: flex;
    text-align: center;
    justify-content: space-between;
    align-items: center;
    // padding: 0 50px;

    .title {
      font-size: 20px;
    }

    .right {
      display: flex;
      text-align: center;
      padding-top: 30px;
    }
  }

  .table {
  }

  .dialogBox {
    margin: 0 auto;
  }

  .drawerBox {
    // padding: 20px 40px;

    .rule {
    }
  }
}
</style>


